{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7894c8cf",
   "metadata": {},
   "source": [
    "# `ipywidgets` Interactive Demo\n",
    "\n",
    "Simple demonstration of rendering Interactive widgets in a `jupyterlite` notebook.\n",
    "\n",
    "`ipywidgets` can be installed in this deployment (it provides the\n",
    "@jupyter-widgets/jupyterlab-manager federated extension), but you will need to make your\n",
    "own deployment to have access to other interactive widgets libraries."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff67ea20",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install -q ipywidgets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d6264f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import IntSlider"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fe4bc82",
   "metadata": {},
   "outputs": [],
   "source": [
    "slider = IntSlider()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77549404",
   "metadata": {},
   "outputs": [],
   "source": [
    "slider"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "910b750d",
   "metadata": {},
   "outputs": [],
   "source": [
    "slider"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8858cac",
   "metadata": {},
   "outputs": [],
   "source": [
    "slider.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7d2f576",
   "metadata": {},
   "outputs": [],
   "source": [
    "slider.value = 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc3c5836",
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import IntText, link"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "491a7244",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = IntText()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f641fb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43bbe69a",
   "metadata": {},
   "outputs": [],
   "source": [
    "link((slider, \"value\"), (text, \"value\"));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7de2e991",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Markdown, display\n",
    "from ipywidgets import interact\n",
    "\n",
    "\n",
    "@interact(cookies=slider)\n",
    "def cookies(cookies=slider.value, calories=(0, 150)):\n",
    "    total_calories = calories * cookies\n",
    "    if cookies:\n",
    "        display(\n",
    "            Markdown(\n",
    "                f\"If each cookie contains _{calories} calories_, _{cookies} cookies_ contain **{total_calories} calories**!\"\n",
    "            )\n",
    "        )\n",
    "    else:\n",
    "        display(Markdown(\"No cookies!\"))\n",
    "    if total_calories > 2000:\n",
    "        display(Markdown(\"> Maybe that's too many cookies...\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
